#include "StdAfx.h"
#include "PermutationA.h"



PermutationA::PermutationA(int n):_tab(n)
{
	for (int i=0;i<n;i++)
	{
		_tab[i]=i;
	}

	for (int i=0; i<n; i++)
	{
		int idx1 = rand()%n, idx2= rand()%n,tmp;
		tmp = _tab[idx1];
		_tab[idx1]=_tab[idx2];
		_tab[idx2]=tmp;
	}
}

PermutationA::PermutationA(const PermutationA & p):_tab(p._tab){

}

PermutationA PermutationA::operator=(const PermutationA p){
	if (this != &p)
		_tab = p._tab;
	
	return *this;
}


PermutationA::~PermutationA(void)
{
}


string PermutationA::toString() const{
	stringstream strStream;
	strStream << "Tableau  : \r\n";
	
	for (unsigned int i=0; i<_tab.size(); i++){
		strStream << _tab[i] << "\t";
	}

	 return strStream.str();
}

int PermutationA::operator[](const unsigned int idx)const {
	if ((idx >= 0) & (idx < _tab.size()))
		return _tab[idx];
	else
		throw "index non valide ! ";
}

unsigned int PermutationA::GetTaille() const{
	return _tab.size();
}

std::ostream & operator<<(std::ostream & f , const PermutationA & p){
	f << p.toString();
	return f ;
}